<template>
  <view class="content">
    <view class="box" v-for="(item, index ) in cardList" :key="index">
      <AtListItem
        :hasBorder="false"
        @click="go(item)"
        :title='item.name'
        arrow='right'
        thumb='https://img12.360buyimg.com/jdphoto/s72x72_jfs/t6160/14/2008729947/2754/7d512a86/595c3aeeNa89ddf71.png'
      />
    </view>
    <AtToast :isOpened="showLoading" :text="'正在加载'" :duration="0" status="loading"></AtToast>
  </view>
</template>

<script>
import './card.scss';
import Taro from '@tarojs/taro';
import UserAPI from "../../api/user.js"
export default {
  data() {
    return {
      cardList: [],
      showLoading: true
    }
  },
  mounted(){
    let user_infor = Taro.getStorageSync("userInfor");
    if(user_infor){
      // 获取详细用户信息
      this.getCardList(user_infor.id);
    }else{
      Taro.redirectTo('/pages/recharge/choseUser');
    }
    
  },
  methods: {
    go(val){
      Taro.setStorageSync('choseCardDetails', val);
      Taro.navigateTo({
        url: "/pages/recharge/optionH5" // 小程序为option, POS的h5为optionH5
      });
    },
    async init(){
      const res = await exchange.employeeList();
      if (res.code == 200) {
        this.staffData = res.data;
        this.showStaff = Taro.getStorageSync("rechangeStaff") ? this.staffTitleTransiform(Taro.getStorageSync("rechangeStaff")) : '选择员工';
      } else{
        console.log(res);
      }
    },

    getCardList(id) {
      let data = {
        token: Taro.getStorageSync('token'),
        app_id: Taro.getStorageSync('app_id'),
        id
      };
      UserAPI.getUserDetail(data).then(res => {
        this.showLoading = false;
        if (res.code === 200) {
          // 获取用户油卡列表
          res.data.card_info.forEach(item => {
            item.card_type = 1;
          });
          let obj = {
            id: res.data.card.id,
            type_card_id: res.data.card.id,
            name: "会员卡",
            balance: res.data.card.balance,
            card_type: 0 //充值选项
          };
          res.data.card_info.unshift(obj);
          this.cardList = res.data.card_info;
          //
        } else {
          this.$message(res.msg);
        }
      });
    },
  }
}

</script>
